/*
Author: Sheila Tabuena
Filename: jQutilities.js
Date Created: JUN-14-2009

Contains general utility functions that are compatible with JQuery toolkit, including:
    addJqNode(parent, element, nameId, text) -- creates new node of type "element",
           appends it to "parent", sets name and id attributes of new node to "nameId",
    insertJqNode(sibling, element, nameId, text) -- Creates a new node of the type "element", 
           inserts it right before the node "sibling".
           Sets the name and id attributes of the new node to "nameId".
           If "text" is present, this also creates a text node with "text"
           in it and appends it to the new node. Returns the new node.
    makejQNode(element, nameId, text) -- Creates a new node of the type "element", 
           but does not append it. Useful when node placement must be deferred.
           Sets the name and id attributes of the new node to "nameId".
           If "text" is present, this also creates a text node with "text"
           in it and appends it to the new node. Returns the new node.
*/


/* Creates a new node of the type "element", appends it to "parent".
   Sets the name and id attributes of the new node to "nameId".
   If "text" is present, this also creates a text node with "text"
   in it and appends it to the new node. Returns the new node.
*/
function addJqNode(parent, element, nameId, text)
{
//   var newNode = document.createElement(element);
//   newNode.setAttribute("id",nameId);
//   newNode.setAttribute("name",nameId);
//   if (text != "")
//   {
//      var textNode = document.createTextNode(text);
//      newNode.appendChild(textNode);
//   }
   var newNode = makeJqNode(element, nameId, text);
   newNode.appendTo(parent);
//   parent.appendChild(newNode);
   return newNode;
}


/* Creates a new node of the type "element", inserts it 
   right before the node "sibling".
   Sets the name and id attributes of the new node to "nameId".
   If "text" is present, this also creates a text node with "text"
   in it and appends it to the new node. Returns the new node.
*/
function insertJqNode(sibling, element, nameId, text)
{
   var newNode = makeJqNode(element, nameId, text);
   sibling.parentNode.insertBefore(newNode,sibling);
   return newNode;
}

/* Creates a new node of the type "element", but does not append it.
   Useful when node placement must be deferred.
   Sets the name and id attributes of the new node to "nameId".
   If "text" is present, this also creates a text node with "text"
   in it and appends it to the new node. Returns the new node.
*/
function makeJqNode(element, nameId, text)
{
   var newNode = jQuery(document.createElement(element)).attr("id",nameId).attr("name",nameId);
   if (text != "")
   {
      jQuery(document.createTextNode(text)).appendTo(newNode);
   }
   return newNode;
}
